// pages/coupon/coupon.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
      active:0,
      showUseDesc: false,
      noUse:[],
      used:[],
      invalid:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.selectComponent("#loading").show()
       const id = options.cardId
       console.log(id)
        //const id = "78693"
       this.getData(id)
    },
    getData(id){
        const that = this
       
        wx.request({
          url: app.globalData.apiUrlNew + 'Mini/BalUpdated.ashx?action=listVoucher',
          data: {
            cardId:id,
          },
          dataType: 'json',
          header: {
            'content-type': 'application/json' // 默认值
          },
          success(resroom) {
              that.selectComponent("#loading").hide()
              if(resroom.data.getNum == 0){
                that.sortCoupon(resroom.data.dtVoucher)
              }
          },
          fail(resfail) {
              that.selectComponent("#loading").hide()
              Toast.fail(resfail.data)
          }
      }) 
    },
    //优惠券分类
    sortCoupon(arr){
      let noUse=[], used=[], invalid=[]
      arr.map(item=>{
        if(item.vdet_status == 2){
          noUse.push(item)
        }else if(item.vdet_status == 3){
          invalid.push(item)
        }else{
          used.push(item)
        }
      })
      this.setData({
        noUse:noUse,
        invalid:invalid,
        used:used
      }) 

    },
    onChange(event) {
      console.log(event)
      // wx.showToast({
      //   title: `切换到标签 ${event.detail.name}`,
      //   icon: 'none',
      // });
    },
    onClose(){
      this.setData({
        showUseDesc:false
      })
    },
    onUseBtn(){
      this.setData({
        showUseDesc:true
      })
    }

     
})